package dao;

import java.util.Date;
import java.util.List;
import java.util.Set;

import model.JsfClass;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * JsfClass entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see model.JsfClass
 * @author MyEclipse Persistence Tools
 */

public class JsfClassDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(JsfClassDAO.class);
	// property constants
	public static final String NAME = "name";
	public static final String PLACE = "place";
	public static final String CLIENT_NUM_NOW = "clientNumNow";
	public static final String CLIENT_NUM_MAX = "clientNumMax";
	public static final String DETAIL = "detail";
	public static final String PRICE_EVERYONE = "priceEveryone";
	public static final String PROFIT = "profit";
	public static final String PASSED = "passed";
	public static final String UNCHECKREASON = "uncheckreason";
	public static final String CLASSROOM_NUM = "classroomNum";

	public void save(JsfClass transientInstance) {
		log.debug("saving JsfClass instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(JsfClass persistentInstance) {
		log.debug("deleting JsfClass instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public JsfClass findById(java.lang.Integer id) {
		log.debug("getting JsfClass instance with id: " + id);
		try {
			JsfClass instance = (JsfClass) getSession().get("model.JsfClass",
					id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(JsfClass instance) {
		log.debug("finding JsfClass instance by example");
		try {
			List results = getSession().createCriteria("model.JsfClass")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding JsfClass instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from JsfClass as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByPlace(Object place) {
		return findByProperty(PLACE, place);
	}

	public List findByClientNumNow(Object clientNumNow) {
		return findByProperty(CLIENT_NUM_NOW, clientNumNow);
	}

	public List findByClientNumMax(Object clientNumMax) {
		return findByProperty(CLIENT_NUM_MAX, clientNumMax);
	}

	public List findByDetail(Object detail) {
		return findByProperty(DETAIL, detail);
	}

	public List findByPriceEveryone(Object priceEveryone) {
		return findByProperty(PRICE_EVERYONE, priceEveryone);
	}

	public List findByProfit(Object profit) {
		return findByProperty(PROFIT, profit);
	}

	public List findByPassed(Object passed) {
		return findByProperty(PASSED, passed);
	}

	public List findByUncheckreason(Object uncheckreason) {
		return findByProperty(UNCHECKREASON, uncheckreason);
	}

	public List findByClassroomNum(Object classroomNum) {
		return findByProperty(CLASSROOM_NUM, classroomNum);
	}

	public List findAll() {
		log.debug("finding all JsfClass instances");
		try {
			String queryString = "from JsfClass";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public JsfClass merge(JsfClass detachedInstance) {
		log.debug("merging JsfClass instance");
		try {
			JsfClass result = (JsfClass) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(JsfClass instance) {
		log.debug("attaching dirty JsfClass instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(JsfClass instance) {
		log.debug("attaching clean JsfClass instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}